package org.study.seatatcc.order.service;

import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.seata.rm.tcc.api.*;
import org.study.seatatcc.order.model.Order;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2024年01月25日
 */
@LocalTCC
public interface OrderService extends IService<Order> {
    /**
     * 下单：创建订单、减库存，涉及到两个服务
     */
    @TwoPhaseBusinessAction(name = "placeOrder", commitMethod = "busCommit", rollbackMethod = "busRollback", useTCCFence = true)
    void placeOrder(@BusinessActionContextParameter(paramName = "userId") String userId,
                    @BusinessActionContextParameter(paramName = "commodityCode") String commodityCode,
                    @BusinessActionContextParameter(paramName = "count") Integer count,
                    boolean throwEx);

    /**
     * 下单：提交事务
     */
    boolean busCommit(BusinessActionContext actionContext);

    /**
     * 下单：回滚事务
     */
    boolean busRollback(BusinessActionContext actionContext);

    /**
     * 下单：创建订单、扣账户，涉及到两个服务
     */
    void create(String userId, String commodityCode, Integer count);
}
